package com.xmmj.baselibrary.utils.viewadapter.smartrefreshview

import androidx.databinding.BindingAdapter
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener
import com.scwang.smart.refresh.layout.listener.OnRefreshListener

@BindingAdapter(value = ["onRefreshLoadMoreListener"], requireAll = false)
fun setRefreshLoadMoreListener(
    refreshLayout: SmartRefreshLayout,
    onRefreshLoadMoreListener: OnRefreshLoadMoreListener?
) {
    onRefreshLoadMoreListener.let {
        refreshLayout.setOnRefreshLoadMoreListener(it)
    }
}

@BindingAdapter(value = ["onRefreshListener", "onLoadMoreListener"], requireAll = false)
fun setRefreshLoadMoreListener(
    refreshLayout: SmartRefreshLayout,
    onRefreshListener: OnRefreshListener?,
    onLoadMoreListener: OnLoadMoreListener?
) {
    onRefreshListener.let {
        refreshLayout.setOnRefreshListener(it)
    }
    onLoadMoreListener.let {
        refreshLayout.setOnLoadMoreListener(it)
    }
}